package com.cherish.meeting.common.api;

/**
 * @author: wuhong-016
 * @time: 2021/3/3 12:11
 * @version: v1.0.0
 * @description:TODO
 */
public class HttpResult {

    private int code;
    private String msg;
    private Object data;

    public HttpResult() {
        this.code = 200;
        this.msg = "SUCCESS";
    }

    /**
     * 请求成功时的响应结果
     *
     * @return
     */
    public static HttpResult success() {
        return new HttpResult();
    }

    /**
     * 请求成功时的响应结果
     *
     * @param msg 自定义响应内容
     * @return
     */
    public static HttpResult success(String msg) {
        return new HttpResult().setMsg(msg);
    }

    /**
     * 请求成功时的响应结果
     *
     * @param data 要响应的数据
     * @return
     */
    public static HttpResult success(Object data) {
        return new HttpResult().setData(data);
    }

    /**
     * 请求成功时的响应结果
     *
     * @param msg  自定义响应的内容
     * @param data 自定义响应数据
     * @return
     */
    public static HttpResult success(String msg, Object data) {
        return new HttpResult().setMsg(msg).setData(data);
    }

    /**
     * 请求失败时的响应内容
     *
     * @return
     */
    public static HttpResult failed() {
        return new HttpResult().setCode(500).setMsg("soething is wrong");
    }

    /**
     * 请求失败时的相应内容
     *
     * @param msg 自定义相应内容
     * @return
     */
    public static HttpResult failed(String msg) {
        return new HttpResult().setCode(500).setMsg(msg);
    }


    public int getCode() {
        return code;
    }

    public HttpResult setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public HttpResult setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public Object getData() {
        return data;
    }

    public HttpResult setData(Object data) {
        this.data = data;
        return this;
    }

}
